package com.guigu.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.base.entity.TruckType;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.base.mapper.TruckTypeMapper;
import com.guigu.base.service.TruckTypeService;
import com.guigu.common.utils.Constant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 车辆类型表 服务实现类
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-08
 */
@Service
public class TruckTypeServiceImpl extends ServiceImpl<TruckTypeMapper, TruckType> implements TruckTypeService {

    /**
     * 添加车辆类型
     *
     * @param TruckType 车辆类型信息
     * @return 车辆类型信息
     */
    @Override
    public TruckType saveTruckType(TruckType TruckType) {
        baseMapper.insert(TruckType);
        return TruckType;
    }

    /**
     * 获取车辆类型分页数据
     *
     * @param page            页码
     * @param pageSize        页尺寸
     * @param name            类型名称
     * @param allowableLoad   车型载重
     * @param allowableVolume 车型体积
     * @return 线路类型分页数据
     */
    @Override
    public IPage<TruckType> findByPage(Integer page, Integer pageSize, String name, BigDecimal allowableLoad, BigDecimal allowableVolume) {
        Page<TruckType> iPage = new Page(page, pageSize);
        LambdaQueryWrapper<TruckType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(name)) {
            lambdaQueryWrapper.like(TruckType::getName, name);
        }
        if (allowableLoad != null) {
            lambdaQueryWrapper.eq(TruckType::getAllowableLoad, allowableLoad);
        }
        if (allowableVolume != null) {
            lambdaQueryWrapper.eq(TruckType::getAllowableVolume, allowableVolume);
        }
        lambdaQueryWrapper.eq(TruckType::getStatus, Constant.DATA_DEFAULT_STATUS);
        return baseMapper.selectPage(iPage, lambdaQueryWrapper);
    }

    /**
     * 获取车辆类型列表
     *
     * @param ids
     * @return 车辆类型列表
     */
    @Override
    public List<TruckType> findAll(List<String> ids) {
        LambdaQueryWrapper<TruckType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ids != null && ids.size() > 0) {
            lambdaQueryWrapper.in(TruckType::getId, ids);
        }
        lambdaQueryWrapper.eq(TruckType::getStatus, Constant.DATA_DEFAULT_STATUS);
        return baseMapper.selectList(lambdaQueryWrapper);
    }
}
